<template>
  <div class="dhhb">
    <div class="login-head">
      <span style="color: #fff" @click="jumpFn()">
        <van-icon name="arrow-left"
      /></span>
      <span class="login-title">兑换红包</span>
      <span></span>
    </div>
    <div class="dhhb-content">
      <div style="text-align: center">
        <input type="text" placeholder="请输入兑换码" />
      </div>

      <input type="text" placeholder="验证码" />
      <div class="yzm">
        <div>
          <img
            :src="imgCode"
            alt=""
            style="margin-left: 0.2973rem"
            @click="getCode()"
          />
        </div>
        <div style="font-size: 0.3243rem; margin-left: 5px" @click="getCode()">
          <p style="color: #666">看不清</p>
          <p>换一张</p>
        </div>
      </div>
    </div>
    <div class="bottom-btn">
    <van-button type="primary" @click="login()">兑换</van-button>
    </div>
  </div>
</template>

<script>

export default {
  name: "dhHb",
  data() {
    return {
      input: "",
      imgCode: "",
    };
  },
  mounted() {
    this.getCode();
  },
  methods: {
    jumpFn() {
      this.$router.back();
    },
    getCode() {
      let api = `https://elm.cangdu.org/v1/captchas`;
      this.$http({
        url: api,
        method: "post",
        data: {},
        withCredentials: true,
      }).then((res) => {
        this.imgCode = res.data.code;
      });
    },
    login() {
      let api = `https://elm.cangdu.org/v1/users/1/hongbao/exchange`;
      this.$http({
        url: api,
        method: "post",
        user_id: 1,
        withCredentials: true,
      }).then((res) => {
        console.log(res);
        console.log(res.data.message);
        if (res.data.message) {
          $(".login-btn").attr("id", "error");
          new TipBox({ type: "error", str: "无效的验证码", hasBtn: true });
        } else {
          $(".login-btn").attr("id", "success");
          new TipBox({ type: "success", str: "验证成功", hasBtn: true });
        }
      });
    },
  },
  created() {},
};
</script>

<style scoped>
.bottom-btn button{
    width: 95%;
}
.bottom-btn{
    text-align: center;
    margin-top: 0.5405rem;
}
.login-head {
  width: 100%;
  height: 1.2576rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #0092e8;
  position: fixed;
  top: 0;
  left: 0;
}
.login-title {
  color: white;
  position: relative;
  left: -0.5405rem;
  font-size: 0.5405rem;
}
.dhhb {
  width: 100%;
  height: 100%;
  background-color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 21;
  background-color: #f5f5f5;
}
.dhhb-content {
  margin-top: 1.3514rem;
}
.dhhb-content input:nth-child(1) {
  border: none;
  outline: none;
  width: 93%;
  height: 1.2162rem;
  font-size: 0.4865rem;
  margin-top: 0.5405rem;
  border-radius: 0.1351rem;
}
/* .oppo{
    display: flex;
    justify-items: space-between;
} */
.dhhb-content input:nth-child(2) {
  border: none;
  outline: none;
  width: 4.973rem;
  height: 1.2162rem;
  font-size: 0.4865rem;
  margin-top: 0.5405rem;
  border-radius: 0.1351rem;
  margin-left: 0.3784rem;
}
.yzm {
  background-color: #fff;
  width: 3.9189rem;
  height: 1.2162rem;
  position: absolute;
  left: 5.8108rem;
  top: 3.6486rem;
  display: flex;
  justify-items: space-between;
  align-items: center;
}
</style>